import React, { useEffect,useState } from "react";
import {getMessageList} from '../api/messages'
export default function Messages() {
    /* 定义状态     一定要传初始值*/
    const [messageList, setMessageList] = useState([]);
    useEffect(() => {
        /* 请求为异步   用匿名函数自执行 */
        (async () => {
            const result = await getMessageList();
            setMessageList(result);
        })();
    },[])
  return (
    <div>
      <ul>
        {messageList.map((item) => (
          <li key={item.id}>
                <a href="/home/message/1">{item.title}</a> &nbsp;&nbsp;
            <button>push</button>
            &nbsp;
            <button>replace</button>
          </li>
        ))}
      </ul>
      <button>前进</button>
      <button>后退</button>
    </div>
  );
}
